﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mvcfluentcontrols.Models;

namespace mvcfluentcontrols.Controllers
{
    public class LookupDataController : Controller
    {
        //
        // GET: /LookupData/
        private static List<LookupData> _LookupData;
        public static List<LookupData> LookupData
        {
            get
            {
                if (_LookupData == null)
                {
                    _LookupData = new List<LookupData>();

                    for (int i = 0; i < 5; i++)
                    {
                        LookupType type = new LookupType { Name = "Country" };
                        _LookupData.Add(new LookupData
                                            {
                            LookupType = type,
                            Name = "Country-" + i.ToString(),
                            Value = i.ToString()
                        });

                    }

                    for (int i = 0; i < 10; i++)
                    {
                        LookupType type = new LookupType { Name = "City" };
                        _LookupData.Add(new LookupData
                                            {
                            LookupType = type,
                            Name = "City-" + i.ToString(),
                            Value = i.ToString()
                        });

                    }
                }
                return _LookupData;
            }
        }

        public JsonResult FillData(string lookupType, string term, int langID)
        {
            // langID kullanacak şekilde entity değiştirilecek.
            var data = LookupData.Where(q => q.LookupType.Name == lookupType && q.Name.StartsWith(term));
            return Json(data.Select(q => new { q.Value, value = q.Name }), JsonRequestBehavior.AllowGet);
        }

    }
}
